<template>
  <base-breadcrumb>
    <searchData
      :search-data="searchArr"
      @search="search"
    />

    <a-card :bordered="false">
      <!-- <title-name title="设计资源项目部评价列表" /> -->

      <div class="pub-table-select-count">
        <a-icon
          type="info-circle"
          theme="twoTone"
        />
        <span style="margin-right: 12px">
          设计资源总数：<span class="totalNum">{{ totalDels.total }} 个</span> |
          待评价审批：<span class="totalNum">{{ totalDels.toReviewNum }} 个</span> |
          审批中：<span class="totalNum">{{ totalDels.underReviewNum }} 个</span> |
          审批通过：<span class="totalNum">{{ totalDels.reviewNum }} 个</span> |
          审批不通过：<span class="totalNum">{{ totalDels.unReviewNum }} 个</span>
        </span>
        <span
          style="float:right;color:#108EE9"
          @click="toggle"
        >
          {{ expand === true ? '展开详细汇总信息' : '收起详细汇总信息' }}
          <a-icon :type="expand ? 'down' : 'up'" />
        </span>
      </div>

      <div
        v-if="expand === false"
        class="wrapper"
      >
        <div class="row">
          <div class="name">
            评价总分平均分
          </div>
          <div class="name">
            进度管理平均分
          </div>
          <div class="name">
            设计质量平均分
          </div>
          <div class="name">
            设计成本管理平均分
          </div>
          <div class="name">
            设计团队平均分
          </div>
          <div class="name">
            合同履约平均分
          </div>
          <div class="name">
            设计创新管理平均分
          </div>
          <div class="name">
            其他加分项平均分
          </div>
        </div>
        <div class="row">
          <div class="name">
            {{ delsScore.totalAveScore || 0 }}
          </div>
          <div class="name">
            {{ delsScore.controlAveScore || 0 }}
          </div>
          <div class="name">
            {{ delsScore.qualityAveScore || 0 }}
          </div>
          <div class="name">
            {{ delsScore.costManageAveScore || 0 }}
          </div>
          <div class="name">
            {{ delsScore.teamAveScore || 0 }}
          </div>
          <div class="name">
            {{ delsScore.performanceAveScore || 0 }}
          </div>
          <div class="name">
            {{ delsScore.composeAveScore || 0 }}
          </div>
          <div class="name">
            {{ delsScore.otherAveScore || 0 }}
          </div>
        </div>
      </div>

      <list-table
        ref="table"
        bordered
        size="default"
        :row-key="record=>record.id"
        :columns="columns"
        :request="loadData"
        :alert="true"
        show-size-changer
        show-quick-jumper
        show-pagination="auto"
      >
        <span
          slot="serial"
          slot-scope="text, record, index"
        >{{ index + 1 }}</span>
        <span
          slot="action"
          slot-scope="text, record"
        >
          <MoreButton>
            <a
              v-btnPermission="'ds_011_loo_01'"
              @click="handleDels(record)"
            >查看</a>
            <template v-if="record.statusCode === 0">
             <a
                v-btnPermission="'ds_011_eva_02'"
                @click="handleEdit(record)"
              >评价</a>
            </template>
            <span
              v-if="record.statusCode === 2||record.statusCode === 3"
              v-btnPermission="'ds_011_adj_03'"
            >
              <a @click="handleEdit(record)">调整</a>
            </span>
            <span v-if="record.statusCode === 1 ||record.statusCode === 2|| record.statusCode === 3">
              <a @click="hadnleApprova(record)">审批信息</a>
            </span>
          </MoreButton>
        </span>
        <template
          slot="contractScope"
          slot-scope="text"
        >
          <ellipsis
            :length="30"
            tooltip
          >
            {{ text }}
          </ellipsis>
        </template>
      </list-table>
    </a-card>
  </base-breadcrumb>
</template>

<script>
import { STable, Ellipsis } from '@/components'
import { getTypes } from '@/api/commons'
import {
  getDesignResourceEvaluateList,
  getDesignResourceEvaluateTotal,
  getResourceEvaluateDeltailsTotal
} from '@/api/project/branchEvaluate'
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import OrgTreeSelect from '@/components/OrgTreeSelect'

const columns = [
  {
    title: '序号',
    width: '65px',
    scopedSlots: { customRender: 'serial' }
  },
  {
    title: '设计资源名称',
    dataIndex: 'designResourceName'
  },
  {
    title: '设计资源类型',
    dataIndex: 'designResourceType'
  },
  {
    title: '项目',
    dataIndex: 'projectName'
  },
  {
    title: '项目设计管理类别',
    dataIndex: 'designTypeName'
  },
  {
    title: '分公司',
    dataIndex: 'branchComName'
  },
  {
    title: '年度时间',
    dataIndex: 'year'
  },
  {
    title: '评价时间',
    dataIndex: 'evaluateTime'
  },
  {
    title: '合同范围',
    dataIndex: 'contractScope',
    // scopedSlots: { customRender: 'contractScope' }
  },
  {
    title: '评价总分',
    dataIndex: 'totalScore'
  },
  {
    title: '进度管理得分',
    dataIndex: 'controlScore'
  },
  {
    title: '设计质量得分',
    dataIndex: 'qualityScore'
  },
  {
    title: '设计成本管理得分',
    dataIndex: 'costManageScore'
  },
  {
    title: '设计团队得分',
    dataIndex: 'teamScore'
  },
  {
    title: '合同履约得分',
    dataIndex: 'performanceScore'
  },
  {
    title: '设计创新管理得分',
    dataIndex: 'composeScore'
  },
  {
    title: '其他加分项得分',
    dataIndex: 'otherScore'
  },
  {
    title: '评价等级',
    width: '100px',
    dataIndex: 'assessmentLevel'
  },
  {
    title: '状态',
    width: '110px',
    dataIndex: 'statusName'
  },
  {
    title: '操作',
    dataIndex: 'action',
    width: '220px',
    fixed: 'right',
    scopedSlots: { customRender: 'action' }
  }
]

export default {
  name: 'a' + Date.now(),
  components: {
    Ellipsis,
    STable
  },
  data() {
    return {
      columns,
      searchArr: [
        // 搜索框
        {
          name: '设计资源名称',
          value: 'designResourceName',
          type: 'input'
        },
        {
          name: '评价时间',
          value: 'createdTime',
          type: 'dateRange'
        },
        {
          name: '项目名称',
          value: 'projectName',
          type: 'input'
        },
        {
          name: '所属单位',
          valueKey: 'searchQuery',
          type: OrgTreeSelect,
        },
        // {
        //   name: '分公司',
        //   valueKey: 'branchComId',
        //   type: SelectSubCompany
        // },
        {
          name: '状态',
          value: 'statusCode',
          type: 'select',
          data: [
            {
              value: 0,
              label: '待评价审批'
            },
            {
              value: 1,
              label: '审批中'
            },
            {
              value: 2,
              label: '审批通过'
            },
            {
              value: 3,
              label: '审批不通过'
            }
          ]
        },
        {
          name: '项目设计管理类别',
          value: 'designManageTypeId',
          type: 'select',
          data: []
        },
        {
          name: '年度时间',
          value: 'year',
          type: 'year'
        }
      ],
      data: [],
      queryParam: {
        evaluationTypeCode: '25001'
      },
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        if (this.queryParam.createdTime && this.queryParam.createdTime.length > 0) {
          this.queryParam.evaluateStartTime = this.queryParam.createdTime[0].format('YYYY-MM-DD')
          this.queryParam.evaluateEndTime = this.queryParam.createdTime[1].format('YYYY-MM-DD')
          delete this.queryParam.createdTime
        }
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        return getDesignResourceEvaluateList(requestParameters).then((res) => {
          return res
        })
      },

      totalDels: {}, // 统计
      delsScore: {}, // 汇总统计
      expand: true
    }
  },

  created() {
    this.getDesignResourceEvaluateTotalReq()
    this.getDesignType()
  },
  computed: {},
  methods: {
    // 获取搜索项目设计管理类别
    getDesignType() {
      getTypes({ type: 9 }).then((res) => {
        this.searchArr[5].data = this.getChangeDatatTypes(res.data)
      })
    },

    // 详情汇总
    toggle() {
      this.expand = !this.expand
      this.getResourceEvaluateDeltailsTotalReq()
    },

    // 条件搜索
    search(val) {
      this.queryParam = val
      this.queryParam.evaluationTypeCode = '25001'
      this.$refs.table.refresh(true)
      this.getDesignResourceEvaluateTotalReq()
      this.getResourceEvaluateDeltailsTotalReq()
    },

    // 列表统计
    getDesignResourceEvaluateTotalReq() {
      console.log(this.queryParam)
      getDesignResourceEvaluateTotal(this.queryParam).then((res) => {
        this.totalDels = res.data
      })
    },

    // 详情汇总统计
    getResourceEvaluateDeltailsTotalReq() {
      getResourceEvaluateDeltailsTotal(this.queryParam).then((res) => {
        if (res.code == 200) {
          this.delsScore = res.data
        }
      })
    },

    // 详情
    handleDels(val) {
      this.$router.push({ path: '/project/design/projectEvaluate/details', query: { id: val.id } })
    },

    // 编辑
    handleEdit(val) {
      this.$router.push({ path: '/project/design/projectEvaluate/edit', query: { id: val.id } })
    },
    /**
     * @description: 审批信息
     * @param {object} record
     * @return {void}
     */
    hadnleApprova(record) {
      this.$bus.$emit('showApprovalDetailsDialog', record.id)
    }
  }
}
</script>


<style scoped type="text/css">
.wrapper {
  overflow: hidden;
  padding: 10px 15px;
  margin-bottom: 20px;
}
.row .name {
  border: 1px solid #686868;
  height: 35px;
  line-height: 35px;
  width: 12.5%;
  float: left;
  margin-right: -1px;
  margin-top: -1px;
  text-align: center;
  font-weight: bold;
  display: block;
}
</style>

